package com.kfm.am.hashtable;

import java.util.Enumeration;
import java.util.Hashtable;

public class HashtableTest {

    public static void main(String[] args) {
        Hashtable<String , String> hashtable = new Hashtable<>(); // 初始容量 11 加载因子 0.75
        Hashtable<Integer, String> hashtable1 = new Hashtable<>(16); // 16， 加载因子0.75
        Hashtable<Integer, String> hashtable2 = new Hashtable<>(16, 0.8f); // 16, 0.8
        hashtable.put("1", "《长风渡》"); // 用key的hasCode值对底层数组的长度取余
        hashtable.put("4", "《开发喵大电影》");
        hashtable.put("3", "《甄嬛传》");
        hashtable.put("2", "《还珠格格》");
        hashtable.put("5", "《还珠格格》");
        hashtable.put("6", "《还珠格格》");
        hashtable.put("7", "《还珠格格》");
        hashtable.put("8", "《还珠格格》");
        hashtable.put("9", "《还珠格格》");
        hashtable.put("10", "《还珠格格》");
        hashtable.put("11", "《还珠格格》");
        hashtable.put("12", "《还珠格格》");
        hashtable.put("13", "《还珠格格》");
        System.out.println(hashtable);
//        Hashtable<Integer, String> hashtable3 = new Hashtable<>(hashtable);
        hashtable.forEach((k, v) -> {
            System.out.println(k.hashCode());
            System.out.println(k + "-->" + v);
        });
        // 获取值的枚举
        Enumeration<String> elements = hashtable.elements();
        while (elements.hasMoreElements()) { // 此枚举类中是否还有元素 类比 迭代器的hasNext()
            String s = elements.nextElement(); // 获取当前的元素 类比 迭代器的next()
            System.out.println(s);
        }

        Enumeration<String > keys = hashtable.keys();
        while (keys.hasMoreElements()) {
            System.out.println(keys.nextElement());
        }
    }
}
